#include <iostream>
#include <vector>
#include "Filter.h"

using namespace std;

FilterImp::FilterImp()
#ifdef DEBUG_EVPROC
, EventProcessorImp(true,"Filter") // comment to remove debug
#endif
{
  RegisterMessageProcessor(FilterMessage::type, &FilterThis, 1 /*priority*/);
  RegisterMessageProcessor(DieMessage::type, &Die, 0 /*priority*/);
}

MESSAGE_HANDLER_DEFINITION_BEGIN(FilterImp, FilterThis, FilterMessage)
		
	cout<<"Filtering on the prime "<<msg.prime<<endl;

	for(int i = 0;i < msg.stream.vec.size();++i){
		if(msg.stream.vec.at(i)%msg.prime == 0){
			msg.stream.vec.erase(msg.stream.vec.begin()+i);
		}
	}

	EventProcessor myInterfClone;
	myInterfClone.CopyFrom(evProc.myInterface);
        DoneMessage_Factory(msg.sender, 1, msg.stream,myInterfClone);


MESSAGE_HANDLER_DEFINITION_END

MESSAGE_HANDLER_DEFINITION_BEGIN(FilterImp, Die, DieMessage)
	
	cout<<"My job is done - Filter "<<endl;
	evProc.EventProcessorImp::processDieMessage(evProc,msg);

MESSAGE_HANDLER_DEFINITION_END
